home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / C++ AppleLink Messages / CPlus.Dev$ 12⁄22⁄89 / 0023-What gives here?-Dec89 < prev    next >
Encoding:
Text File  |  1989-12-20  |  1.9 KB  |  72 lines  |  [TEXT/GEOL]

  1. Item forwarded  by  SCHMUCKER1   to NASSI
  2.  
  3. Item    3184957                         16-Dec-89        18:57
  4.  
  5. From:   D2022                           Strata, Gary Bringhurst,PRT
  6.  
  7. To:     CPLUS.APPLE$                    C++ Interest List--Apple Employees
  8.         CPLUS.DEV$                      C++ Interest List--Developers
  9.  
  10. cc:     MACDTS                          Macintosh Developer Tech. Supt.
  11.  
  12. Sub:    What gives here?
  13.  
  14. When the C++ compiler is given the following class definitions:
  15.  
  16. ----
  17.  
  18. class A {
  19.    virtual void foo(int& i) = 0;
  20.    virtual void foo(char& c) = 0;
  21. };
  22.  
  23. class B : public A {
  24.    void foo(int& i);
  25.    void foo(char& c);
  26.    virtual void foo(float& f) = 0;
  27.    virtual void foo(double& d) = 0;
  28. };
  29.  
  30. class C : public B {
  31.    void foo(float& f);
  32.    void foo(double& d);
  33. };
  34.  
  35. ----
  36.  
  37. it reacts with these warnings:
  38.  
  39. File "test.h"; line 15 # warning:  C::foo() hides virtual B::foo() of type
  40. void B:: (int &)
  41. File "test.h"; line 15 # warning:  C::foo() hides virtual B::foo() of type
  42. void B:: (char &)
  43.  
  44. What gives here?  My intent is that the pure virtual methods of class A be
  45. defined within class B, which then adds two new pure virtual methods, which are
  46. defined in class C.  Class C is the only non-abstract class among the three.
  47. Note that the following modification to class C will get rid of the warnings:
  48.  
  49. ----
  50.  
  51. class C : public B {
  52.    void foo(int& i);
  53.    void foo(char& c);
  54.    void foo(float& f);
  55.    void foo(double& d);
  56. };
  57.  
  58. ----
  59.  
  60. If I have the first two methods simply call their counterparts in class B I get
  61. the behaviour I want, but at the expense of an additional jsr.  Why does the
  62. compiler force me to redefine these methods?  Am I missing something here?
  63. It's very common to build new abstract classes upon other abstract classes,
  64. while providing incremental functionality.  Any answers are appreciated.
  65.  
  66. Thanks in advance.
  67.  
  68. Gary L. Bringhurst
  69. Strata Inc.
  70. D2022
  71.  
  72.